package com.smarttest.base

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import com.smarttest.main.MainRepository
import com.smarttest.main.MainViewModel

/**
 * viewmodel的通用提供类
 * Created by 28510 on 2018/3/14.
 */
class ViewModelFactory<T>(vararg args: T) : ViewModelProvider.NewInstanceFactory() {
    private val args = args
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
            return MainViewModel(args[0] as MainRepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}
